package com.znsd.stu.controllor;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.znsd.entitys.Cwj_SpecialtyInfo;
import com.znsd.entitys.TimeTable;
import com.znsd.entitys.Users;
import com.znsd.stu.service.Cwj_TimeTableService;

@Controller
public class Cwj_TimeTableControllor {
	@Autowired
	private Cwj_TimeTableService times;
	@RequestMapping(value = "gotime", method = RequestMethod.GET)
	public String gotime(HttpServletRequest  request) {
		return "admin/timetable";
	}
	
	@ResponseBody
	@RequestMapping("timeList")
	public Map<String,Object> timeList(HttpServletRequest  request) {
		HttpSession session=request.getSession();
		Map<String,Object> map=new HashMap<String,Object>();
		Users users=(Users) session.getAttribute("user");
		List<TimeTable> list=times.getAll(users.getUser_id());
		int count=times.getcount(users.getUser_id());
		map.put("rows",list);
		map.put("total",count);
		return map;
	}
	@RequestMapping(value = "updatetime", method = RequestMethod.GET)
	public String updatetime(Integer mytid,HttpServletRequest  request) {
		HttpSession session=request.getSession();
		System.out.println(mytid);
		session.setAttribute("tid",mytid);
		return "admin/updatetime";
	}
	@RequestMapping(value = "addtime", method = RequestMethod.POST)
	public String addtime(String uptime,String breaktime,
			String Latetime,String ontime,String offtime,Integer hiddenId) {
		System.out.println(uptime+","+breaktime+","+Latetime+","+ontime+","+offtime+","+hiddenId);
		times.updatetime(uptime, breaktime, Latetime, ontime, offtime, hiddenId);
		return "admin/timetable";
	}
	@ResponseBody
	@RequestMapping("getTimeById")
	public Map<String,Object> getTimeById(HttpServletRequest  request) {
		Map<String,Object> map=new HashMap<String,Object>();
		HttpSession session=request.getSession();
		int mytid=(int) session.getAttribute("tid");
		System.out.println(mytid);
		TimeTable timetables=times.getById(mytid);
		map.put("list", timetables);
		return map;
	}
}
